#pragma once
#include <vector>
#include <string>


/// 方案和码表共用结构
struct UIBaseInfo{
    unsigned int id = 0;  
    std::string name; 
    bool enable = false; //是否被使用，只是给码表用 
    int candidate_count = 5;  // 候选词数量

    void reset(){
        id = 0;
        name.clear();
        enable = false;
        candidate_count = 5;
    }
};

//码表一个词条的数据
struct WubiCodetableData{
    unsigned int id = 0;
    std::string word;
};

class UIIpcClient;
class IpcMsgHelper
{
    friend class UIIpcClient; // 允许UIIpcClient访问私有构造函数和私有membe
private:
    IpcMsgHelper(UIIpcClient *client) : _ipc_clent(client) {}

public:
    // 交换码表顺序
    bool swapCodeTableOrder(unsigned int id1, unsigned int id2);
    //根据编码获取指定码表的词
    bool getCodeTableDataByCode(unsigned int codeTableId, const std::string& code, 
                              std::vector<WubiCodetableData>& outData);
    //交换码表词条的顺序
    bool swapCodeTableDataOrder(unsigned int codeTableId, 
                              unsigned int codeId1, unsigned int codeId2);
    //在指定码表中添加词条
    bool addWord(unsigned int codeTableId, const std::string& code,
               const std::string& word, unsigned int& newCodeId);
    //删除词条
    bool removeWord(unsigned int codeId);

    //获取所有方案
    bool getAllSchemes(std::vector<UIBaseInfo>& schemes);

    //新增方案
    bool createScheme(const std::string& name, unsigned int& newId);
    //更新方案
    bool updateScheme(unsigned int id, const std::string& name, int candidateCount);
    //删除方案
    bool deleteScheme(unsigned int id);

    //获取指定方案的码表
    bool getCodeTables(unsigned int schemeId, std::vector<UIBaseInfo>& tables);
    
    //创建码表
    bool addCodeTable(unsigned int schemeId, const std::string& name, 
                    const std::string& filePath, unsigned int& newTableId);

    //设置默认方案
    bool setCurrentSchemeId(unsigned int id);

    //获取候选词列表
    bool getCandidateList(const std::string& code, std::vector<std::string>& candidates);
    
    //获取当前激活的方案id
    bool getCurrentSchemeId(unsigned int& outId);

    //让服务器重新加载词库
    bool reloadWordDic(); 

    //删除码表
    bool removeCodeTable(unsigned int schemeId, unsigned int codeTableId);

    // 设置码表启用状态
    bool setCodeTableEnable(unsigned int codeTableId, bool enable);

    // 新增编码反查接口
    bool getCodeByWord(const std::string& word, std::vector<std::string>& out_codes);
    
    // 新增导出码表接口
    bool exportCodeTable(unsigned int codeTableId, const std::string& filePath);

private:
    UIIpcClient *_ipc_clent;
};